const fs = require('fs');
const path = require('path');
const Mock = require('mockjs');
const JSON5 = require('json5');
const moment = require('moment');

//读取json5文件，解析并返回
function getJsonFile(filePath) {
  //读取指定json文件
  var json = fs.readFileSync(path.resolve(__dirname, filePath), 'utf-8');
  //解析并返回
  return JSON5.parse(json);
}

//暴露出一个函数
module.exports = function(app) {
  //判断当前环境，如果是dev环境并设置MOCK=true的时候才有mock数据(看第四步配置)
  if (process.env.VUE_APP_MOCK == 'true') {

    app.post('/login', (req, res) => {
      var json = getJsonFile("./login/login_1.json5");
      res.json(Mock.mock(json));
    })
    app.get('/UserControl', (req, res) => {
      var json = getJsonFile("./UserControl/UserControl_1.json5");
      res.json(Mock.mock(json));
    })
    app.put('/modify_status', (req, res) => {
      var json = getJsonFile("./modify_status/modify_status.json5");
      res.json(Mock.mock(json));
    })
    app.get('/tep', (req, res) => {
      var json = getJsonFile("./updata.json5");
      res.json(Mock.mock(json));
    })

  }


}
